***********************************************************************************

use  "Data_temp/polit_involv.dta", clear


* Create globals for table labels
global index			 \hline  \\ \multicolumn{4}{l}{Index of political preferences} \\ \cmidrule{1-1}
global party_closer1 	 \hline  \\ \multicolumn{4}{l}{Supporting a political party or close to one party} \\ \cmidrule{1-1}
global interest_polit	 \hline  \\ \multicolumn{4}{l}{Interested in politics} \\ \cmidrule{1-1}
global vote_agree		 \hline  \\ \multicolumn{1}{l}{Agree that voting is a social norm} \\ \cmidrule{1-1}
global vote_party		 \hline  \\ \multicolumn{1}{l}{States a party to vote for} \\ \cmidrule{1-1}
global member_party	 	\hline  \\ \multicolumn{4}{l}{Member of a political party} \\ \cmidrule{1-1}


cap erase "Tables/tb2.tex"

estimates clear
foreach var in index   party_closer1 interest_polit vote_agree vote_party member_party { 

			
		* before first election		
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age100,-24,24), gen(dummy)
			drop dummy1
		
		rdrobust `var' age100 if age100!=0  , p(1) h(24)  covs(dummy*)
			est sto mx
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)		
				
		* first year		
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age0,-24,24) & rel_year>=0, gen(dummy)
			drop dummy1
		
		rdrobust `var' age0 if age0!=0  & rel_year>=0, p(1) h(24)  covs(dummy*)
			est sto m0
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age1,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age1 if age1!=0, p(1) h(24)  covs(dummy*)
			est sto m1
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age2,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age2 if age2!=0, p(1) h(24) covs(dummy*)
			est sto m2
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
			
		cap drop dummy*
		quiet tab year if `var'<. & inrange(age3,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' age3 if age3!=0, p(1) h(24) covs(dummy*)
			est sto m3
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
	
		cap drop dummy*
		quiet tab year if `var'<. & inrange(rel_age2,-24,24), gen(dummy)
			drop dummy1
			
		rdrobust `var' rel_age2 if rel_age2!=0, p(1) h(24) covs(dummy*)
			est sto m4
			estadd scalar eff_obs=e(N_h_l)+e(N_h_r)
	
		estout m* using "Tables/tb2.tex", ///
			style(tex) cells (b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
			starlevels( * 0.1 ** 0.05 *** 0.01)  varlabels(RD_Estimate "${`var'} RD estimate")	  ///
			stats(eff_obs, fmt(%9.0gc) labels("N"))    mlabels(none) ///
			collabels(none) eql(none) notype label append 	
	
		}
		